//
//  StoreInformationThreeTableViewCell.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/10.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "StoreInformationThreeTableViewCell.h"
#import "MyStoreInformationModel.h"
#import "GLGWTagsView.h"

@implementation StoreInformationThreeTableViewCell
{
    GLGWView *baV;
    GLGWLabel *topLab;
    GLGWLabel *middleLab;
    GLGWTagsView * topTageView;
    GLGWTagsView * bottomTageView;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        GLGWView *baView = [[GLGWView alloc] initWithInSuperView:self.contentView];
        baView.backgroundColor = [UIColor whiteColor];
        [baView setViewShadowWidth:3 theCornerRadius:12];
        [baView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(kHeightProportion_In_iPhoneTriploid(10));
            make.left.equalTo(self.contentView).offset(kHeightProportion_In_iPhoneTriploid(15));
            make.right.equalTo(self.contentView).offset(-kHeightProportion_In_iPhoneTriploid(15));
            make.bottom.equalTo(self.contentView).offset(-kHeightProportion_In_iPhoneTriploid(10));
        }];
        baV = baView;
        
        GLGWButton *deleBtn = [[GLGWButton alloc] initInSuperView:baView];
//        deleBtn.backgroundColor = kRandomColor;
        [deleBtn setImage:[UIImage imageNamed:@"icon_quxiaofenlei"] forState:UIControlStateNormal];
        [deleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.right.equalTo(baView);
            make.height.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(16)));
        }];
        [deleBtn addTarget:self action:@selector(deletAction:) forControlEvents:UIControlEventTouchUpInside];
        
        GLGWLabel *topLa = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:kColor_Rule_Black inSuperView:baView];
        topLa.text = @"管材 ";
        [topLa mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(baView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(baView.mas_top).offset(kWidthProportion_In_iPhoneTriploid(12));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(17)));
        }];
        topLab = topLa;
        
        GLGWLabel *lab = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:kColor_Rule_Black inSuperView:baView];
        lab.text = @"钢厂";
        [lab mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(baView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
//            make.top.equalTo(topLa.mas_bottom).offset(kWidthProportion_In_iPhoneTriploid(6));
            make.bottom.equalTo(baView.mas_bottom).offset(-kHeightProportion_In_iPhoneTriploid(38));
        }];
//        lab.numberOfLines = 0;
        middleLab = lab;
        
    }
    return self;
}

- (void)setModel:(MyStoreInformationProsAndFactory *)model
{
    _model = model;
    FFTagsViewConfig *config = [self tagViewConfig];
    
    if (topTageView) {
        [topTageView removeFromSuperview];
        topTageView = nil;
    }
    
    if (bottomTageView) {
        [bottomTageView removeFromSuperview];
        bottomTageView = nil;
    }
    if (model.categoryName) {
        topLab.text = model.categoryName;        
    }
    NSArray *topArr = [model.productName componentsSeparatedByString:@","];
    NSArray *bottomArr = [model.factoryName componentsSeparatedByString:@","];
    topTageView = [[GLGWTagsView alloc] initWithFrame:CGRectMake(kWidthProportion_In_iPhoneTriploid(6), kHeightProportion_In_iPhoneTriploid(35), KScreenWidth - kWidthProportion_In_iPhoneTriploid(30), 0) tagsArray:topArr config:config tagBackImgStr:@""];
    [baV addSubview:topTageView];
    
    CGFloat taH = [topTageView heighttagsArray:topArr config:[self tagViewConfig]] + topTageView.y + kHeightProportion_In_iPhoneTriploid(33);
    bottomTageView = [[GLGWTagsView alloc] initWithFrame:CGRectMake(kWidthProportion_In_iPhoneTriploid(6), taH, KScreenWidth - kWidthProportion_In_iPhoneTriploid(30), 0) tagsArray:bottomArr config:config tagBackImgStr:@""];
    CGFloat hei = [self cellHeightWith:bottomArr];
    [middleLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(33))).priorityMedium();
        make.top.equalTo(self->topTageView.mas_bottom);
        make.left.equalTo(self->topLab.mas_left);
        make.bottom.equalTo(self->baV.mas_bottom).offset(-hei);
    }];
    
    [baV addSubview:bottomTageView];
}

- (FFTagsViewConfig *)tagViewConfig
{
    FFTagsViewConfig *config = [[FFTagsViewConfig alloc] init];
    config.itemHeight = kHeightProportion_In_iPhoneTriploid(20);
    config.itemHerMargin = kWidthProportion_In_iPhoneTriploid(0);
    config.itemVerMargin = kHeightProportion_In_iPhoneTriploid(6);
    config.hasBorder = NO;
    config.itemContentEdgs = 0;
    config.topBottomSpace = 0.1;
    config.fontSize = 14.0;
    config.isCanSelected = YES;
    config.isCanCancelSelected = NO;
    config.isMulti = YES;
    config.normalTitleColor = [UIColor colorWithHexString:@"#666666"];
    config.selectedTitleColor = [UIColor colorWithHexString:@"#666666"];
    return config;
}

- (void)deletAction:(GLGWButton *)sender
{
    if (self.BlcokDelete) {
        self.BlcokDelete(sender, self.index);
    }
}

- (CGFloat)cellHeightWith:(NSArray *)bottomArr
{
    CGFloat bottomH = [bottomTageView heighttagsArray:bottomArr config:[self tagViewConfig]];
    CGFloat maxY = kHeightProportion_In_iPhoneTriploid(18) + bottomH;
    return maxY;
}

//- (CGFloat)cellHeight
//{
////    [self layoutIfNeeded];
//
//    CGFloat topH = [topTageView heighttagsArray:self.dataArr[0] config:[self tagViewConfig]];
//    CGFloat bottomH = [bottomTageView heighttagsArray:self.dataArr[1] config:[self tagViewConfig]];
//
//    CGFloat maxY = kHeightProportion_In_iPhoneTriploid(35) + topH + bottomH + kHeightProportion_In_iPhoneTriploid(33) + kHeightProportion_In_iPhoneTriploid(12);
//    return maxY;
//
//}

@end
